<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>问题上报看板</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <el-row class="header">
      <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
      <el-col :span="12" class="header-title" id="">问题上报看板</el-col>
      <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
    </el-row>

    <div style="padding:10px;">
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'">
        <el-form-item label="分厂:" prop="factoryid">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择" filterable @change="factorySelectChange"
            style="width:170px;">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="责任单位:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择" clearable filterable style="width:170px;">
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="ufccreatedate" label="问题提出时间:">
          <el-date-picker v-model="queryInfo.ufccreatedate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择" filterable style="width:170px;">
            <el-option :key="'未处理'" :label="'未处理'" :value="'1'"></el-option>
            <el-option :key="'处理中'" :label="'处理中'" :value="'2'"></el-option>
            <el-option :key="'处理完'" :label="'处理完'" :value="'3'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="getData">查询</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column label="分厂" prop="factoryname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="问题描述" prop="description" show-overflow-tooltip></el-table-column>
        <el-table-column label="问题类型" prop="ufccontent" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="问题提出人" prop="createemployee" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="问题提出时间" prop="ufccreatedate" width="120" :formatter="splitDate"></el-table-column>
        <el-table-column label="要求完成日期" prop="ufcchulidate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="责任单位" prop="resworkcentername" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="责任人" prop="resfullname" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column label="状态" prop="ufcstatus" width="100" show-overflow-tooltip>
          <template slot-scope="scope" v-if="scope.row.ufcstatus">
            <el-tag type="danger" v-if="scope.row.ufcstatus === '未处理'">{{scope.row.ufcstatus}}</el-tag>
            <el-tag type="warning" v-else-if="scope.row.ufcstatus === '处理中'">{{scope.row.ufcstatus}}</el-tag>
            <el-tag type="success" v-else-if="scope.row.ufcstatus === '处理完'">{{scope.row.ufcstatus}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="处理意见" prop="ufcresult" show-overflow-tooltip></el-table-column>
        <el-table-column label="超期时间" prop="delayday" width="100" show-overflow-tooltip>
          <template slot-scope="scope">
            <span v-if="scope.row.delayday > 0" style="color:red;">{{scope.row.delayday}} 天</span>
            <span v-else>{{scope.row.delayday}} 天</span>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[16,50,100]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>

  <script type="module">
    import { exportExcelData, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { getFactory, getWorkcenterList } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',// 当前时间
        loading: false,
        loadingText: '拼命加载中',
        title: '',// 看板标题
        queryInfo: {
          factoryid: '',
          workcenterid: '',
          ufccreatedate: [],
          status: '',
          currentPage: 1,//当前页
          pageSize: 14 //每页显示条数
        },
        total: 0,
        dataList: [],
        factoryList: [],
        workcenterList: [],
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        async factorySelectChange(factoryid) {
          if (factoryid === '全部') return;
          this.queryInfo.workcenterid = null
          if (factoryid) {
            this.workcenterList = await getWorkcenterList({ factoryid: factoryid || this.queryInfo.factoryid });
          }
        },
        async getData() {
          this.loading = true
          this.loadingText = '数据加载中...'
          const { data: { data, meta, total } } = await axios.post('../handler/board/UfcProblemDashBoard.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) {
            return this.$message.error(meta.msg)
          }
          this.dataList = data;
          this.total = total;
        },
        //监听 currentpage 改变
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        //监听 pagezie 改变
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        this.factoryList = await getFactory();
        const { factoryid } = this.factoryList[0];
        this.queryInfo.factoryid = factoryid;
        this.workcenterList = await getWorkcenterList({ factoryid });
        this.getData();
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>